package com.mxnet.chongjin.supoman.fragment;


import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

import com.mxnet.chongjin.supoman.R;
import com.mxnet.chongjin.supoman.config.Api;
import com.mxnet.chongjin.supoman.utils.ToastUtils;

/**
 * A simple {@link Fragment} subclass.
 */
public class OperateVideoFragment extends Fragment {
    private Context mContext;
    private VideoView mVideoView;
    private Bundle mBundle;

    public OperateVideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_operate_video, container, false);
        mContext = getContext();
        initView(v);
        return v;
    }

    public void initView(View view) {
        mBundle = getArguments();
        final String videoUrl = mBundle.getString("video");
        mVideoView = view.findViewById(R.id.vv_operate_video);
        mVideoView.setVideoURI(Uri.parse(Api.URL_HEADER + Api.GET_IMAGE + videoUrl));
        mVideoView.setMediaController(new MediaController(mContext));
        mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                ToastUtils.showToast(mContext, "播放结束!");
            }
        });


    }
}
